<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="text" placeholder="请输入对联的下一句">
  <button>qudrt</button>
  <script>
    var input = document.querySelector('input')
    var but = document.querySelector('button')
    var str = new XMLHttpRequest()
    str.open('get', 'https://apis.tianapi.com/duilian/index?key=9ba87a578dc98e0b476e678b912e1dec')
    str.send()
    str.onreadystatechange = function (res) {
      if (str.readyState == 4 && str.status == 200) {
        let a = JSON.parse(str.responseText)
        alert(`上句: ` + a.result.content.split('，')[0])
        but.onclick = function () {
          if (input.value == a.result.content.split('，')[1]) {
            alert('正确')
          } else {
            alert('错误')
          }
        }
      }
    }
  </script>
</body>

</html>